libkovan
1
The kovan standard library
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
socket.hpp
Go to the documentation of this file.
1
#ifndef _WIN32
2
3
#ifndef _SOCKET_HPP_
4
#define _SOCKET_HPP_
5
6
#ifndef _WIN32
7
#include <netinet/in.h>
8
#else
9
#ifndef _WIN32_WINNT
10
#define _WIN32_WINNT 0x0501
11
#endif
12
#include <winsock2.h>
13
#include <winsock.h>
14
typedef
u_long socklen_t;
15
#endif
16
17
#include <unistd.h>
18
19
typedef
int
socket_fd_t
;
20
21
struct
sockaddr;
22
23
class
Address
24
{
25
public
:
26
Address
(
const
char
*
const
host,
const
unsigned
short
port
);
27
Address
(
const
sockaddr_in &
addr
);
28
Address
();
29
30
bool
isValid
()
const
;
31
32
bool
setHost
(
const
char
*
const
host);
33
void
setPort
(
const
unsigned
short
port);
34
35
unsigned
short
port
()
const
;
36
37
const
sockaddr *
addr
()
const
;
38
socklen_t
addrLength
()
const
;
39
40
const
char
*
ip
()
const
;
41
42
private
:
43
bool
m_valid;
44
sockaddr_in m_addr;
45
};
46
47
class
Socket
48
{
49
public
:
50
Socket
();
51
52
bool
open
(
int
domain,
int
type,
int
protocol);
53
bool
isOpen
()
const
;
54
bool
setBlocking
(
const
bool
blocking);
55
bool
setReusable
(
const
bool
reusable);
56
bool
bind
(
const
unsigned
short
port);
57
bool
connect
(
const
Address
&addr);
58
bool
disconnect
();
59
60
bool
close
();
61
62
ssize_t
recv
(
void
*
const
buffer,
const
size_t
length,
int
flags = 0);
63
ssize_t
recvfrom
(
void
*
const
buffer,
const
size_t
length,
Address
&address,
int
flags = 0);
64
65
ssize_t
send
(
const
void
*
const
buffer,
const
size_t
length,
int
flags = 0);
66
ssize_t
sendto
(
const
void
*
const
buffer,
const
size_t
length,
const
Address
&dest,
int
flags = 0);
67
68
socket_fd_t
fd
()
const
;
69
70
static
Socket
udp
();
71
static
Socket
tcp
();
72
73
private
:
74
socket_fd_t
m_fd;
75
};
76
77
#endif
78
79
#endif
include
kovan
socket.hpp
Generated on Mon Aug 19 2013 00:33:00 for libkovan by
1.8.4